package com.elmcode.study.controller;

import com.elmcode.study.entity.UserEntity;
import com.elmcode.study.exception.ParamsException;
import com.elmcode.study.utils.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
public class HelloController {


    @GetMapping("/hello")
    public String hello(){
        UserEntity userEntity = new UserEntity();
        userEntity.setId(1L);
        userEntity.setUserName("张三");
        userEntity.setGender("男");
        return userEntity.toString();
    }


    @GetMapping("/map/test")
    public Result mapTest(@RequestParam Map<String,Object> params) throws ParamsException {

        if(params == null || params.size() == 0){
            throw new ParamsException("请传入参数");
        }

//        int i = 5/0;

        UserEntity userEntity = new UserEntity();
        userEntity.setId(1L);
        userEntity.setUserName("张三");
        userEntity.setGender("男");
        return Result.ok("成功",userEntity);
    }


    @GetMapping("/success.html")
    public String success(){

        return "success";
    }


}
